/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cliente;

import conUDP.SocketUDP;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.SocketException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author douglas
 */
public class ThreadSinal extends Thread {

    private SocketUDP socket;
    private DatagramPacket pacote_recebe, pacote_envia;
    // private String signal;

    public ThreadSinal() {
        //signal = "ON";

        try {
            socket = new SocketUDP(55555);
        } catch (SocketException ex) {
            Logger.getLogger(ThreadAtualizaLista.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    @Override
    public void run() {
        while (true) {
            try {
                byte[] sinal = new byte[2];
                byte[] solicitacao = new byte[3];//RECEBE "ON?"
                sinal = "ON".getBytes();
               // System.out.println("IP LOCAL" + socket.getLocalAddress() + ":" + "PORTA LOCAL" + socket.getLocalPort());
                pacote_recebe = new DatagramPacket(solicitacao, solicitacao.length);
                pacote_envia = new DatagramPacket(sinal, sinal.length, ConexaoCliente.getIpServer(), 33333);
                socket.recebe(pacote_recebe, pacote_envia);

            } catch (InterruptedException ex) {
                Logger.getLogger(ThreadSinal.class.getName()).log(Level.SEVERE, null, ex);
            } catch (IOException ex) {
                Logger.getLogger(ThreadSinal.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
}
